<?php
// 添加用户
function addUserInfo($userObj) {
  // 第一个参数是服务器名 第二个是用户名  第三个是密码  第四个是数据库名
  $mysql = new mysqli(SAE_MYSQL_HOST_M.":".SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS,SAE_MYSQL_DB);
  $mysql->query("set names utf8");
  $openid = $userObj->openid;
  $country = $userObj->country;
  $province = $userObj->province;
  $city = $userObj->city;
  $nickname = $userObj->nickname;
  $headimgurl = $userObj->headimgurl;
  $sexNum = $userObj->sex;
  if($sexNum == 1){
    $sex = "男";
  }elseif($sexNum == 2){
    $sex = "女";
  }else{
    $sex = "未知";
  }

  $sql = "INSERT INTO happyer(openid,country,province,city,nickname,headimgurl,sex) VALUES('{$openid}','{$country}','{$province}','{$city}','{$nickname}','{$headimgurl}','{$sex}')";
  $result = $mysql->query($sql);
  if ($result) {
    return "用户信息插入成功";
  }else {
    return "用户信息插入失败";
  }
  $mysql->close();
}










 ?>
